<!-- 菜单详情 -->
<template>
  <el-dialog v-if="props.show" :model-value="props.show" title="菜单详情" :close-on-click-modal="false" :close-on-press-escape="false"
    top="25vh" width="5%" @close="onHideDetails">
    <div class="padding20">
      <el-form ref="ruleFormRef" :model="data" :inline="true" :rules="rules">
        <form-item title="菜单ID" :pass="true" value="id">
          <el-input class="width240" type="text" v-model="data.id" :disabled="true"/>
        </form-item>
        <form-item title="菜单名称" :pass="true" value="title">
          <el-input class="width240" type="text" v-model="data.title" clearable/>
        </form-item>
        <form-item title="菜单Path" :pass="true" value="path">
          <el-input class="width240" type="text" v-model="data.path" clearable/>
        </form-item>
        <form-item title="菜单排序" :pass="true" value="sort">
          <el-input class="width240" type="number" v-model="data.sort" clearable/>
        </form-item>
        <form-item title="菜单状态" :pass="true" value="status">
          <el-radio-group v-model="data.status" size="large">
            <el-radio-button label="关闭" :value="0" />
            <el-radio-button label="开启" :value="1" />
          </el-radio-group>
        </form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="info" @click="onHideDetails">取 消</el-button>
        <el-button type="primary" @click="gameSet(ruleFormRef)">确 定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { getOperatorTiger, editTiger } from '@/api/game'
import { throttle } from '@/utils/index'
const props = defineProps({
  show: {
    type: Boolean,
    default: () => {
      return false
    }
  },
  checkedItem: {
    type: Object,
    default: () => {
      return {}
    }
  }
})

watch(
  () => [props.checkedItem,props.show],
  async (value) => {
    if (value[0]) {
      Object.assign(data,props.checkedItem)
    }
  },
)

const data = reactive({
  id: 0,
  title: '',
  path: '',
  sort: 0,
  status: 1,
})

// 设置
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules<typeof data>>({
  title: [{ required: true, message: '请输入中文(Chinese)名称', trigger: 'blur' }],
})
const gameSet = throttle(async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let res = await editTiger(data,false);
      ElMessage.success('修改成功')
      emit('onHideDetails', true)
    }
  })
}, 3000)

// 重置
const emit = defineEmits(['onHideDetails'])
const onHideDetails = () => {
  emit('onHideDetails', false)
}
</script>

<style scoped lang="scss"></style>
